Vue.component('Update', {
	template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="数字人id" prop="meta_id">
							<el-input  v-model="form.meta_id" autoComplete="off" clearable  placeholder="请输入数字人id"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="名字" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入名字"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="形象" prop="model_id">
							<el-select   style="width:100%" v-model="form.model_id" filterable clearable placeholder="请选择形象">
								<el-option v-for="(item,i) in model_ids" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="语音合成" prop="ttsType_id">
							<el-select   style="width:100%" v-model="form.ttsType_id" filterable clearable placeholder="请选择语音合成">
								<el-option v-for="(item,i) in ttsType_ids" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="语音识别" prop="sttType_id">
							<el-select   style="width:100%" v-model="form.sttType_id" filterable clearable placeholder="请选择语音识别">
								<el-option v-for="(item,i) in sttType_ids" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="语言模型" prop="chat_id">
							<el-select   style="width:100%" v-model="form.chat_id" filterable clearable placeholder="请选择语言模型">
								<el-option v-for="(item,i) in chat_ids" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="模型角色ID" prop="role_id">
							<el-input  v-model="form.role_id" autoComplete="off" clearable  placeholder="请输入模型角色ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="账号" prop="username">
							<el-input  v-model="form.username" autoComplete="off" clearable  placeholder="请输入账号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="唤醒词" prop="wakeup_keyword">
							<Tag v-if="show" :tag_list.sync="form.wakeup_keyword"></Tag>
							<label style="color:#999;font-size:12px;">最多7个唤醒词，每个唤醒词长度建议4-6个字符</label>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="头像" prop="avatar">
							<Upload v-if="show" size="small"  upload_type="1" file_ext="jpg,png,jpeg"   file_type="image" cropsize="300,300" :image.sync="form.avatar"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="详细信息" prop="basicInformation">
							<wang-editor v-if="show"   :wangcontent.sync="form.basicInformation"></wang-editor>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="开场白" prop="openingLine">
							<el-input  type="textarea" autoComplete="off" v-model="form.openingLine"  :autosize="{ minRows: 2, maxRows: 2}" clearable placeholder="请输入开场白"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="强制要求" prop="traits">
							<el-input  type="textarea" autoComplete="off" v-model="form.traits"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入强制要求"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="状态" prop="status">
							<el-radio-group v-model="form.status">
								<el-radio :label="1">正常</el-radio>
								<el-radio :label="0">禁用</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="创建时间" prop="create_time">
							<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="datetime" v-model="form.create_time" clearable placeholder="请输入创建时间"></el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
			form: {
				meta_id:'',
				name:'',
				model_id:'',
				ttsType_id:'',
				sttType_id:'',
				chat_id:'',
				role_id:'',
				username:'',
				wakeup_keyword:[],
				avatar:'',
				basicInformation:'',
				openingLine:'',
				traits:'',
				status:1,
				create_time:'',
				update_time:'',
			},
			model_ids:[],
			ttsType_ids:[],
			sttType_ids:[],
			chat_ids:[],
			loading:false,
			rules: {
				meta_id:[
				],
				name:[
					{required: true, message: '名字不能为空', trigger: 'blur'},
				],
				model_id:[
					{required: true, message: '形象不能为空', trigger: 'change'},
				],
				ttsType_id:[
					{required: true, message: '语音合成不能为空', trigger: 'change'},
				],
				sttType_id:[
					{required: true, message: '语音识别不能为空', trigger: 'change'},
				],
				chat_id:[
					{required: true, message: '语言模型不能为空', trigger: 'change'},
				],
				username:[
					{required: true, message: '账号不能为空', trigger: 'blur'},
				],
				wakeup_keyword:[
					{required: true, message: '唤醒词不能为空', trigger: 'blur'},
				],
				avatar:[
					{required: true, message: '头像不能为空', trigger: 'blur'},
				],
				basicInformation:[
					{required: true, message: '详细信息不能为空', trigger: 'blur'},
				],
				openingLine:[
					{required: true, message: '开场白不能为空', trigger: 'blur'},
				],
				status:[
					{required: true, message: '状态不能为空', trigger: 'change'},
				],
			}
		}
	},
	watch:{
		show(val){
			if(val){
				axios.post(base_url + '/Meta/Ue/getFieldList').then(res => {
					if(res.data.status == 200){
						this.model_ids = res.data.data.model_ids
						this.ttsType_ids = res.data.data.ttsType_ids
						this.sttType_ids = res.data.data.sttType_ids
						this.chat_ids = res.data.data.chat_ids
					}
				})
			}
		}
	},
	methods: {
		open(){
			this.form = this.info
			this.setDefaultVal('wakeup_keyword')
			this.form.create_time = parseTime(this.form.create_time)
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Meta/Ue/update',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		setDefaultVal(key){
			if(this.form[key] == null || this.form[key] == ''){
				this.form[key] = []
			}
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
